package com.bjsxt.set;

import java.util.HashSet;
import java.util.Set;

public class TestSet1 {

    public static void main(String[] args) {

        //任何对象放入HashSet、LinkedHashSet等底层结构有哈希表的集合中，必须重写hashCode和equals方法
        Set<Student> set = new HashSet<>();

        Student s1 = new Student("张三", 20, '1');
        Student s2 = new Student("李四", 21, '2');
        Student s3 = new Student("王五", 22, '3');
        Student s4 = new Student("赵六", 24, '4');
        Student s5 = new Student("王五", 22, '3');

        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        set.add(s5);

        System.out.println(set.size());
        for (Student s : set) {
            System.out.println(s);
        }
    }
}
